package org.viettan.android.main.managers;

import java.util.List;

import org.viettan.android.main.io.EntityRetrievalException;
import org.viettan.android.main.io.NetworkUtility;
import org.viettan.android.main.io.UrlUtility;
import org.viettan.android.main.model.Campaign;
import org.viettan.android.main.xml.CampaignXmlParser;

import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
 * Singleton to manage retrieving the campaigns from the Viet Tan website feed.
 */
@Singleton
public class CampaignManager extends BaseEntityManager<Campaign> {

    @Inject
    private final UrlUtility urlUtility;

    @Inject
    CampaignManager(UrlUtility urlUtility, NetworkUtility networkUtility,
	    CampaignXmlParser xmlParser) {
	super(networkUtility, xmlParser);
	this.urlUtility = urlUtility;
    }

    /**
     * Returns the list of recently-uploaded {@link Campaign}s in reverse-chronological order.
     *
     * @param useCache
     *            retrieve the data from the cache if it is there
     * @return List of {@link Campaign}s recently uploaded
     * @throws EntityRetrievalException
     */
    public List<Campaign> getCampaigns(boolean useCache) throws EntityRetrievalException {
	return getEntities(urlUtility.getActionFeed(), useCache);
    }
}
